package com.ruoyi.forum.service.impl;

import java.util.Date;
import java.util.List;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.forum.domain.ForumStudent;
import com.ruoyi.forum.service.IForumStudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.forum.mapper.ForumPostMapper;
import com.ruoyi.forum.domain.ForumPost;
import com.ruoyi.forum.service.IForumPostService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 论坛-贴子Service业务层处理
 * 
 * @author ruoyi
 * @date 2024-02-11
 */
@Service
public class ForumPostServiceImpl implements IForumPostService 
{
    @Autowired
    private ForumPostMapper forumPostMapper;

    @Autowired
    private IForumStudentService forumStudentService;


    /**
     * 查询论坛-贴子
     * 
     * @param id 论坛-贴子主键
     * @return 论坛-贴子
     */
    @Override
    public ForumPost selectForumPostById(Long id)
    {
        return forumPostMapper.selectForumPostById(id);
    }

    /**
     * 查询论坛-贴子列表
     * 
     * @param forumPost 论坛-贴子
     * @return 论坛-贴子
     */
    @Override
    @Transactional
    public List<ForumPost> selectForumPostList(ForumPost forumPost)
    {
        List<ForumPost> forumPosts = forumPostMapper.selectForumPostList(forumPost);
        for(ForumPost post : forumPosts){
            post.setForumStudent(forumStudentService.selectForumStudentById(post.getUserId()));
        }
        return forumPosts;
    }

    /**
     * 新增论坛-贴子
     * 
     * @param forumPost 论坛-贴子
     * @return 结果
     */
    @Override
    public int insertForumPost(ForumPost forumPost)
    {
        forumPost.setCreateTime(DateUtils.getNowDate());
        return forumPostMapper.insertForumPost(forumPost);
    }

    /**
     * 修改论坛-贴子
     * 
     * @param forumPost 论坛-贴子
     * @return 结果
     */
    @Override
    public int updateForumPost(ForumPost forumPost)
    {
        forumPost.setUpdateTime(DateUtils.getNowDate());
        return forumPostMapper.updateForumPost(forumPost);
    }

    /**
     * 批量删除论坛-贴子
     * 
     * @param ids 需要删除的论坛-贴子主键
     * @return 结果
     */
    @Override
    public int deleteForumPostByIds(Long[] ids)
    {
        return forumPostMapper.deleteForumPostByIds(ids);
    }

    /**
     * 删除论坛-贴子信息
     * 
     * @param id 论坛-贴子主键
     * @return 结果
     */
    @Override
    public int deleteForumPostById(Long id)
    {
        return forumPostMapper.deleteForumPostById(id);
    }


    /**
     * 查询论坛-某一天贴子数量
     *
     * @param date 查询的时间。
     * @return 结果
     */
    @Override
    public int selectForumPostByDate(Date date) {
        return forumPostMapper.selectForumPostByDate(date);
    }
}
